#ifndef __renderer_h__
#define __renderer_h__

#include <stdint.h>
#include <cstdio>

#define VERTS_NUM 100
enum RRPrimType {RR_LINE, RR_LINESTRIP, RR_LINELOOP, RR_TRIANGLE, RR_POLYGON};

#endif

class RRVertex
{
 public:
  float x, y, z, w;
  float c[4];
};

class RRPrim
{
 private:
  RRPrimType t;
  RRVertex verts[VERTS_NUM];
  int verts_index;

 public:
  explicit RRPrim();
  void rrSetType(RRPrimType arg);
  RRPrimType rrGetType();
  void rrSetVert(RRVertex arg);
  RRVertex rrGetVert(int index);
  RRVertex *rrGetVertAdrs(int index);
  int rrGetVertsNum();
};

class RRClipping
{
 private:
  int Xmax, Xmin, Ymax, Ymin;
  RRPrim *prim;
  uint8_t rrOutCode(float x, float y);
  void rrCohenSutherland(RRVertex s, RRVertex t, float Xp, float Yp, float Xq, float Yq);
    
 public:
  explicit RRClipping();
  void rrClipping(RRPrim *src, RRPrim *dest);
};

class RRRenderer
{
 private:
  RRPrim prim1;			/* クリッピングに入れるやつ */
  RRPrim prim2;			/* クリッピングから出てくやつ */
  RRVertex vert;
  float color[4];
  RRClipping clipping;

 public:
  void rrBegin(RRPrimType type);
  void rrEnd();
  void rrSetVert3f(float x, float y, float z);
  void rrColor4f(float a, float r, float g, float b);
  void rrPrintVert(int index);
};
